package com.xbdun.web.bmp.service;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xbdun.comweb.bmp.util.UserInfoUtil;
import com.xbdun.comweb.bmp.util.WebCommonUtil;
import com.xbdun.facade.bmp.request.system.OrgUserRequest;
import com.xbdun.facade.validatebmp.constant.DubboValidateBmpConst;
import com.xbdun.facade.validatebmp.menus.EmailTempletEnum;
import com.xbdun.facade.validatebmp.request.TemplateMailRequest;
import com.xbdun.facade.validatebmp.service.email.EmailFacade;

@Service
public class EmailNotifyService {
	@Reference(registry=DubboValidateBmpConst.REGISTRYS)
	EmailFacade emailFacade;//发送邮件
	
	/**
	* @Title: sendAddOrgUser
	* @Description: 给机构新加入的用户发送邮件
	* @param request    设定文件
	* @return void    返回类型
	 */
	public void sendAddOrgUser(HttpServletRequest httpRequest,OrgUserRequest request){
		try{
			if(StringUtils.isNotBlank(request.getOrgEmail())){
				TemplateMailRequest req = new TemplateMailRequest();
				
				req.setTempletName(EmailTempletEnum.ADD_ORG_USER.getKey());
				req.setSubject("欢迎加入 "+UserInfoUtil.getClient(httpRequest).getOrgName()+" 通知");
				req.setTo(request.getOrgEmail());
				//真实姓名
				req.getTempParams().put("realyName",request.getRealName());
				req.getTempParams().put("orgName",UserInfoUtil.getClient(httpRequest).getOrgName());
				emailFacade.sendTemplateMail(req);
			}
		}catch(Exception e){
			
		}
	}

	//通过审核的企业需要发一份邮件给
	public void orgAuditThrough(String orgName, String orgEmail) {
		TemplateMailRequest req = new TemplateMailRequest();
		
		req.setTempletName(EmailTempletEnum.ADD_ORG_USER.getKey());
		req.setSubject("审核通知，您已经成功通过");
		req.setTo(orgEmail);
		//真实姓名
		req.getTempParams().put("orgName",orgName);
		req.getTempParams().put("webUrl",WebCommonUtil.getLoginUrl());
		emailFacade.sendTemplateMail(req);
	}
}
